package com.example.mymessagequeue.test;

import com.example.mymessagequeue.common.MqException;
import com.example.mymessagequeue.mqclient.Channel;
import com.example.mymessagequeue.mqclient.Connection;
import com.example.mymessagequeue.mqclient.ConnectionFactory;
import com.example.mymessagequeue.mqserver.core.BasicProperties;
import com.example.mymessagequeue.mqserver.core.ExchangeType;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

@Slf4j
public class Consumer {
    public static void main(String[] args) throws IOException, MqException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("127.0.0.1");
        factory.setPort(7772);
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();


        channel.basicConsume("test.queue", true,  new com.example.mymessagequeue.common.Consumer() {
            @Override
            public void handleDelivery(String consumerTag, BasicProperties basicProperties, byte[] body) {
                log.info("messageId = {} body= {} ", basicProperties.getMessageId(), new String(body, 0, body.length));
            }
        });
    }
}
